package cn.ffcs.unm.testClient.httpClient;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.log4j.Logger;

import cn.ffcs.unm.testClient.vo.Input;
import cn.ffcs.uom.common.util.JacksonUtil;
import cn.ffcs.uom.common.util.ServerConfigUtil;

import com.alibaba.fastjson.JSONObject;

public class TestClient {

	private Logger logger = Logger.getLogger(this.getClass());
	public static String REST_STAFF_PWD_UOM_URL = "http://134.64.53.52:9001/uac-service/rest/staffBaseInfo/pwd/";// 统一用户员工密码重置接口地址

	@org.junit.Test
	public void Test() throws Exception {
		HttpClient httpClient = null;
		PostMethod httpPost = null;
		String staffaccount = "H8514451";
		String newPwd = "113f31616a7d76780000313446464353";
		String jsonStr = "{\"staffAccount\":\"" + staffaccount
				+ "\",\"newPasswd\":\"" + newPwd + "\",\"reqSys\": \"13110\"}";
		httpClient = new HttpClient();
		httpPost = new PostMethod(TestClient.REST_STAFF_PWD_UOM_URL);
		StringRequestEntity requestEntity = new StringRequestEntity(jsonStr,
				"application/json", "UTF-8");
		httpPost.setRequestEntity(requestEntity);
		httpClient.executeMethod(httpPost);
		// 测试
		Header[] headers = httpPost.getResponseHeaders();
		for (Header header : headers) {
			logger.info(header.toString());
		}
		// 获取返回的数据
		String statusCode = String.valueOf(httpPost.getStatusCode());
		String returnCode = null;
		if (!"200".equals(statusCode)) {
			returnCode = statusCode;
		}
		httpPost.getParams().setContentCharset("UTF-8");
		String bodyAsString = httpPost.getResponseBodyAsString();
		JSONObject jsonObject = JSONObject.parseObject(bodyAsString);
		returnCode = jsonObject.getString("code");
		String returnMsg = jsonObject.getString("msg");
		logger.info("returnCode:" + returnCode + "   returnMsg:" + returnMsg);
	}

	public static String GZT_URL = "http://127.0.0.1:9001/muiltcompare/";

	@org.junit.Test
	public void GztSfzJk() throws Exception {
		HttpClient httpClient = new HttpClient();
		PostMethod httpPost = new PostMethod(TestClient.GZT_URL);

		Input input = new Input();
		input.setClientSn("201710301429385880000000001");
		input.setGmsfhm("340823199405303112");
		input.setXm("王宜仁");
		input.setSign("0ca175b9c0f726a831d895e269332461");
		String javaBeanJson = input.toString();
		logger.info(javaBeanJson);

		StringRequestEntity requestEntity = new StringRequestEntity(
				javaBeanJson, "application/json", "UTF-8");
		httpPost.setRequestEntity(requestEntity);
		httpClient.executeMethod(httpPost);
		// 获取返回的数据
		String statusCode = String.valueOf(httpPost.getStatusCode());
		String returnCode = null;
		if (!"200".equals(statusCode)) {
			returnCode = statusCode;
			logger.info(returnCode);
		}
		httpPost.getParams().setContentCharset("UTF-8");
		String bodyAsString = httpPost.getResponseBodyAsString();
		JSONObject jsonObject = JSONObject.parseObject(bodyAsString);
		returnCode = jsonObject.getString("resultCode");
		String returnMsg = jsonObject.getString("resultMsg");
		logger.info("returnCode:" + returnCode + "   returnMsg:" + returnMsg);
	}

	@org.junit.Test
	public void test() throws Exception {
		boolean show = ServerConfigUtil.isComponentShow();
		logger.info(show);
		Input input = new Input();
		input.setClientSn("201710301429385880000000001");
		input.setGmsfhm("340823199405303112");
		input.setXm("王宜仁");
		input.setSign("0ca175b9c0f726a831d895e269332461");
		String javaBeanJson = input.toString();
		logger.info(javaBeanJson);
		String json = JacksonUtil.Object2JSon(input);// 将对象转成json格式的字符串
		logger.info(json);
	}

}
